package triggerhelper.helperClasses;

import java.awt.*;
import javax.swing.*;
import triggerhelper.dataHolders.SimpleTrigger;

public class CustomListCellRenderer extends JLabel implements ListCellRenderer {

    public CustomListCellRenderer() {
        setOpaque(true);
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        // Assumes the stuff in the list has a pretty toString
        setText(value.toString());

        // based on the index you set the color.  This produces the every other effect.
        if(value instanceof String){
            setForeground(new Color(0,0,0));
        }
        else if (((SimpleTrigger)value).isSimple()){
            setForeground(new Color(105,16,28));
        }else{
            setForeground(new Color(23,31,96));
        }
        setFont(new Font("calibri", Font.PLAIN, 13));
        if(isSelected){
            setBackground(Color.lightGray);
// <editor-fold defaultstate="collapsed" desc="faild code">
//            if(value instanceof Trigger) {
//                if (!((Trigger)value).getVariables().isEmpty()){
//                    String newValue = ((Trigger)value).getVariables().get(0).getName();
//                    DefaultListModel aModel = (DefaultListModel)list.getModel();
//                    if(!(aModel.getElementAt(index + 1) instanceof String)){
//                        aModel.add(index + 1, newValue);
//                    }
//                }
//            }// </editor-fold>
        }else{
            setBackground(Color.white);
        }
        
        return this;
    }
}
